#!/bin/bash

# last value
for test in Alabama Alaska Arizona Arkansas California Colorado
do
    echo The next state is $test
done
echo "The last state we visited was $test"
test=Connecticut
echo "Wait, now we're visiting $test"

# escape or quote
for test in I don\'t know if "this'll" work
do
    echo "word: $test"
done

# variable & files
states="Alabama Alaska Arizona Arkansas Colorado Connecticut Delaware Florida"
statesfile=states.txt
for state in $states; do
    echo $state >> $statesfile
done
for state in `cat $statesfile`; do
    echo "Visit beautiful $state"
done
rm $statesfile

# directory
for file in ~/.b*; do
    if [ -d "$file" ]; then
        echo "$file is a directory"
    elif [ -f "$file" ]; then
        echo "$file is a file"
    else
        echo "$file doesn't exist"
    fi
done

# c-style
for (( i = 1; i <= 10; i++ )); do
    echo "The next number is $i"
done

# IFS (internal field separator)
IFSOLD=$IFS
IFS=$'\n'
for entry in `cat /etc/passwd`; do
    echo "Values in $entry:"
    IFS=:
    for value in $entry; do
        echo "  $value"
    done
done
IFS=$IFSOLD

